#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include "process.h"

//这是一个刷新的函数指针类型
typedef void (*flush_t)(double total,double current);



const int base = 20;
double total = 2048.0; // 2048MB
double once  = 0.5;    // 0.5MB

void download(flush_t f)
{
	double current = 0.0;
	while(current < total)
	{
		//模拟下载行为
		int r = rand() % base + 1; //[1, base]
		double speed = r * once;
		current += speed;
		if(current >= total)
		{
			current = total;
		}
		usleep(10000);

		//更新除了本次新的下载量
		//根据真实的应用场景,进行动态刷新
		
		//Process(total,current);
		f(total,current);


		//printf("test: %.1lf / %.1lf\r",current,total);
		//fflush(stdout);
	}
	printf("\n");
}


int main()
{
	srand(time(NULL));
	download(FulshProcess);
	download(FulshProcess);
	download(FulshProcess);
	download(FulshProcess);
	//Process();
	return 0;
}

